package com.huangj.pro2_h2pop;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.huangj.entity.HomeInfoEntity;
import com.huangj.fragments.TravPicSeeFragment;
import com.huangj.huangjlibrary.base.BaseActivity;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * Created by HuangJ on 2016/10/8.19:55
 */
public class Lv4Item_PicActivity extends BaseActivity {

    private ArrayList<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.Contents> contents;
    private Lv4ItemPicsAdapter lv4ItemPicsAdapter;


    @BindView(R.id.travel_vp)
    ViewPager viewPager;
    @BindView(R.id.tr_tv1)
    TextView tv1;
    @BindView(R.id.tr_tv2)
    TextView tv2;


    @Override
    protected int getContentId() {
        return R.layout.travelpic_layout;
    }

    @Override
    protected void init() {

        Intent intent = getIntent();
        contents = (ArrayList<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.Contents>) intent.getSerializableExtra("contents");
//      Log.d("print", "init: "+ contents.get(0).getPhoto_url());


       tv2.setText(contents.size()+"");
        lv4ItemPicsAdapter = new Lv4ItemPicsAdapter(getSupportFragmentManager(),contents);
        viewPager.setAdapter(lv4ItemPicsAdapter);
    }

    /**
     * 图片集合的适配器；
     */
    public class Lv4ItemPicsAdapter extends FragmentStatePagerAdapter{
        private ArrayList<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.Contents> contents;

        public Lv4ItemPicsAdapter(FragmentManager fm,ArrayList<HomeInfoEntity.DataBean.SectionsBean.ModelsBean.Contents> contents) {
            super(fm);
            this.contents = contents;
        }

        @Override
        public Fragment getItem(int position) {
            tv1.setText(position+"");
            return TravPicSeeFragment.getIntence(contents.get(position).getPhoto_url());
        }

        @Override
        public int getCount() {
            return contents.size();
        }
    }
}
